<?php

/**
 * 邮箱配置
 */
class MailerAction extends AdminbaseAction {

	//SMTP配置
    public function index() {
    	$this->display();
    }
    
    //SMTP配置处理
    public function index_post() {
    	$_POST = array_map('trim', $_POST);
    	if(in_array('', $_POST)) $this->error("不能留空！");
    	$home_config_file="./data/conf/config.php";
    	if(file_exists($home_config_file)){
    		$home_configs=include $home_config_file;
    	}else {
    		$home_configs=array();
    	}
    	$home_configs['SP_MAIL_ADDRESS'] = $_POST['address'];
    	$home_configs['SP_MAIL_SMTP'] = $_POST['smtp'];
        $home_configs['SP_MAIL_FROMNAME'] = $_POST['fromname'];
    	$home_configs['SP_MAIL_LOGINNAME'] = $_POST['loginname'];
    	$home_configs['SP_MAIL_PASSWORD'] = $_POST['password'];
    	
    	$rst = sp_save_var($home_config_file, $home_configs);
    	if ($rst) {
    		$this->success("保存成功！");
    	} else {
    		$this->error("保存失败！");
    	}
    }
    
    //member账号激活
    public function active(){
    	$where = array('option_name'=>'member_email_active');
    	$option = M('Options')->where($where)->find();
    	if($option){
    		$options = json_decode($option['option_value'], true);
    		$this->assign('options', $options);
    		$this->assign('option_id', $option['option_id']);
    	}
    	$this->display();
    }
    
    public function active_post(){
    	$home_config_file="./data/conf/config.php";
    	if(file_exists($home_config_file)){
    		$home_configs=include $home_config_file;
    	}else {
    		$home_configs=array();
    	}
    	$home_configs['SP_MEMBER_EMAIL_ACTIVE'] = $_POST['lightup'];
    	$rst1 = sp_save_var($home_config_file, $home_configs);

    	if(!empty($_POST['option_id'])) $data['option_id']=intval($_POST['option_id']);
    	$data['option_name'] = "member_email_active";
    	$stripChar = '?<*>\'\"';
    	$_POST['options']['title'] = preg_replace('/['.$stripChar.']/s','',$_POST['options']['title']);
    	$data['option_value']= json_encode($_POST['options']);
    	$rst2 = M('Options')->add($data, array(), true);
    	if ($rst2) {
    		$this->success("保存成功！");
    	} else {
    		$this->error("保存失败！");
    	}
    }
}

?>